﻿//技能逻辑的基类
using System;
using UnityEngine;

public abstract class SkillLogicBase
{
    public SkillDatabase TableData;

    protected Creature _caster;//施法者
    protected Creature _target;
    protected Action _skillEndCallback;//技能结束回调
    protected TimeLine _timeLine = new TimeLine();//技能时间线

    protected SkillCD _skillCD ;
    public float LeftCD { get { return _skillCD.LeftCD; } }

    public bool IsInCD { get { return _skillCD.IsInCD; } }

    public float MaxCD { get { return _skillCD.MaxCD; } }

    public virtual void Init(Creature caster,SkillDatabase tableData)
    {
        _caster = caster;
        TableData = tableData;
        InitTimeLine();
        _skillCD = new SkillCD();
        _skillCD.MaxCD = TableData.CD;
    }
    protected virtual void InitTimeLine()
    {
        Debug.LogError("子类没有初始化时间线"+GetType().ToString());
    }
    public virtual void Start(Creature target, Action skillEndCallback)
    {
        _target = target;
        _skillEndCallback = skillEndCallback;
        _timeLine.Start();
        
    }
    public virtual void Loop()
    {
        _timeLine.Loop(Time.deltaTime);
    }

    protected virtual void onSkillStart(int __null)
    {
        _skillCD.StartCD();
        //Debug.Log("技能释放开始");
        if (_target != null)
        {
            _caster.LookAt(_target);
        }
    }
    protected virtual void onAction(int actionID)
    {
        //Debug.Log("播放动画");
        _caster.SetAnim(actionID);
    }
   
    protected void onActionEnd(int actionID)
    {
        //Debug.Log("动画结束");
        if (_caster.GetAnim() == actionID)
        {
            _caster.SetAnim(0);
        }
    }
    protected virtual void onSkillEnd(int __null)
    {
        //Debug.Log("技能释放完毕:");
        _target = null;
        //通知外界技能结束
        if (_skillEndCallback != null) { _skillEndCallback(); }
    }
}